import { request } from '../../../services/request';
import { SrnBodyQueryParams, SrnBodyResponse } from './types';

export const querySrnBody = async (params: SrnBodyQueryParams): Promise<SrnBodyResponse> => {
    console.log('请求参数:', params);

    try {
        const response = await request('/app/wms/srn/send/querySend', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('接口返回:', response);
        return response;
    } catch (error) {
        console.error('查询 SrnBody 失败:', error);
        throw error;
    }
};

export const confirmAsn = async (params: { id: string; outstore_quantity: number; tracking_number: string; delivery_remark: string }): Promise<any> => {
    console.log('确认发货请求参数:', params);

    try {
        const response = await request('/app/wms/srn/send/send', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('确认发货接口返回:', response);
        return response;
    } catch (error) {
        console.error('确认发货失败:', error);
        throw error;
    }
};

export const getBodyListByBusNum = async (customer_name: string): Promise<any> => {
    try {
        const response = await request('/app/wms/srn/send/querySend', {
            method: 'POST',
            body: JSON.stringify({
                customer_name,
                current: 1,
                size: 100
            }),
        });
        return response;
    } catch (error) {
        console.error('获取销售单号列表失败:', error);
        throw error;
    }
};

// 新增批量发货接口
export const batchSendSrn = async (params: { ids: string[]; tracking_number: string; delivery_remark: string }): Promise<any> => {
    console.log('批量发货请求参数:', params);

    try {
        const response = await request('/app/wms/srn/send/batchSend', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('批量发货接口返回:', response);
        return response;
    } catch (error) {
        console.error('批量发货失败:', error);
        throw error;
    }
};

